package com.andersen.web.controller;

import com.andersen.database.entity.Roles;
import com.andersen.web.service.ComponentTypeTree;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller
public class IndexController extends AbstractController{

    @RequestMapping(value = "/", method = RequestMethod.GET)
      public void loadFirstPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //model.addAttribute("message", "Woo!");
        
        String path = "/components";
        
        if (hasGrantedAuthority(Roles.HR)) {
            path = "/employees";
        }
        if (hasGrantedAuthority(Roles.ADMIN)) {
            path = "/select_user";
        }
        
        RequestDispatcher dispatcher = request.getRequestDispatcher(path);    
        dispatcher.forward(request, response);
    }
    
    /*@RequestMapping(value = "/tree", method = RequestMethod.GET)
      public String printTree(ModelMap model) {
        
        String html = componentTypeService.getComponentTypeTree().toHTML();
        model.addAttribute("tree", html);
        return "tree";
    }*/
    
}
